package com.syt.user.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syt.model.user.UserInfo;
import com.syt.result.Result;
import com.syt.user.service.UserInfoService;
import com.syt.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author xx
 * @since 2023-02-20
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;


    @ApiOperation(value = "认证审批")
    @GetMapping("/approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId, @PathVariable Integer authStatus){
        boolean flag=  userInfoService.updateAuthStatusByUserId(userId,authStatus);
        if (flag) {
            return Result.ok();
        }
        return Result.fail();
    }


    @ApiOperation(value = "用户详情")
    @GetMapping("/show/{userId}")
    public Result userDetails(@PathVariable Long userId){
        Map<String,Object> map= userInfoService.getUserDetailsById(userId);
        return Result.ok(map);
    }

    @ApiOperation(value = "用户是否锁定状态")
    @GetMapping("/lock/{userId}/{status}")
    public Result lockUser(@PathVariable Long userId,@PathVariable Integer status){
        boolean flag=userInfoService.updateUserLockStatusByUserId(userId,status);
        if (flag){
            return Result.ok();
        }else {
            return Result.fail();
        }

    }


     @ApiOperation(value = "用户列表(带条件分页)")
     @GetMapping("/{page}/{limit}")
     public Result  userInfoList(@PathVariable long page,
                                 @PathVariable long limit,
                                 UserInfoQueryVo userInfoQueryVo){
         Page<UserInfo> pageParam = new Page<>(page, limit);
         Page<UserInfo> pageMode = userInfoService.selectUserInfoPage(pageParam,userInfoQueryVo);
         return Result.ok(pageMode);
     }








}
